{extends file="../global.html"}
{block name=body}



 

      
          <div class="content" >
            <!-- 右侧内容框架，更改从这里开始 -->
          
            
            <table class="layui-table">
                <thead>
                    <tr>
                     <th>
                         用户电话
                        </th>
                        <th>
                         商品
                        </th>
                        <th>
                          预约门店
                        </th>
                        <th>
                           姓名
                        </th>
                        <th>
                           性别
                        </th>
                        <th>
                          预约到店时间
                        </th>
                        <th>
                          预约城市
                        </th>
                        <th>
                          预约状态
                        </th>
                    </tr>
                </thead>
                <tbody>
                {foreach $res as $v}
                    <tr class="tr_{$v.subscribe_state}">
                        
                        <td class="td"> {$v.user_phone}</td>
                        <td class="td"><span class="layui-btn layui-btn-radius" onclick="show({$v.goods_id})">{$v.goods_name}</span> </td>
                         <td class="td"> {$v.subscribe_ctiy_name}</td>
                        <td class="td"> {$v.subscribe_name}</td>
                         <td class="td"> {if $v.subscribe_sex == 0}女{else}男{/if}</td>
                        <td class="td" >{$v.subscribe_time|date_format:"%Y-%m-%d"}</td>
                       <td class="td"> {$v.subscribe_city}</td>
                        <td class="td-status">
                          <span state="{$v.subscribe_state}"  onclick="state({$v.subscribe_id})" class="layui-btn show-{$v.subscribe_id} {if $v.subscribe_state == 0}layui-btn-normal  {else} layui-btn-warm{/if}   layui-btn-mini  " state="{$v.subscribe_state}" onclick="show({$v.subscribe_id})"> {if $v.subscribe_state== 0}已处理{else}未处理{/if}</span>
                        </td>
                            
                    </tr>
                   
                   {/foreach}
                </tbody>
            </table>
            <!-- 右侧内容框架，更改从这里结束 -->
            
          </div>
         <script type="text/javascript">
              function show(id){
              // alert(id);
                $.ajax({
                        type:"post",
                        data:{ goods_id:id},
                        url:"{url('run/subscribe/select')}",
                        success:function(v){
                          // console.log(msg);
                              // if(v == true){
                                // console.log(v);
                              var str =  '<table class="layui-table" lay-skin="row"><colgroup><col width="150"><col width="200"><col></colgroup><tbody><tr><td>款型</td><td>'+v.goods_model+'款　'+v.goods_name+'　'+v.goods_describe+'　'+v.goods_car+'</td></tr><tr><td>车型</td><td>'+v.goods_model_car+'</td></tr><tr><td>厂商指导价</td><td>'+v.goods_price+'万</td></tr><tr><td>首付</td><td>'+v.goods_payment+'万</td></tr><tr><td>月供</td><td>'+v.goods_month+'元</td></tr><tr><td>尾款购车</td><td>'+v.goods_retainage+'元</td></tr></tbody></table>';
                                layer.tab({
                                    area: ['600px', '300px'],
                                    tab: [{
                                      title: '详情', 
                                      content: str
                                    }]
                                }); 
                                
                                // }  
                              }
                     

               })
              

           } 


           function state(id){
              var stat = $('.show-'+id).attr('state');
              if(stat==1){
                stat = 0;
                layer.open({
                                  title: '在线调试'
                                  ,content: '<form><textarea style="color:black" name="" id="" cols="30" rows="10"></textarea></form>',
                              }); 


                $('.layui-layer-btn0').click(function(){
                   var text = $('textarea').val();
                   // console.log(text);
                   $.ajax({
                        type:"post",
                        data:{ id:id,state:stat,result:text},
                        url:"{url('run/subscribe/state')}",
                        success:function(msg){
                             if(msg == true){
                            $('.show-'+id).addClass('layui-btn-normal').removeClass('layui-btn-warm').text('已处理').attr('state',stat);
                          }  
                        }
                      })
                })
              }else{
                $.ajax({
                        type:"post",
                        data:{ id:id,state:stat},
                        url:"{url('run/subscribe/find')}",
                        success:function(msg){
                          // console.log(msg);return;
                          if(msg){
                              layer.open({
                                  title: '在线调试'
                                  ,content: '<form><textarea style="color:black" name="" id="" cols="30" rows="10">'+msg["0"].subscribe_result+'</textarea></form>',
                              });
                              $('.layui-layer-btn0').click(function(){
                             var text = $('textarea').val();
                   // console.log(text);
                   $.ajax({
                        type:"post",
                        data:{ id:id,state:stat,result:text},
                        url:"{url('run/subscribe/state')}",
                        success:function(msg){
                             if(msg == true){
                            $('.show-'+id).addClass('layui-btn-normal').removeClass('layui-btn-warm').text('已处理').attr('state',stat);
                          }  
                        }
                      })
                })

                          }
             
                 
          
              // alert(stat)
             
          }

        })
              }
              // alert(stat);
              
            }

          function up(){
              $.ajax({
                        type:"post",
                        data:{ id:id,state:stat},
                        url:"{url('run/subscribe/state')}",
                        success:function(msg){
                          // alert(msg);
                          if(msg == true){
                            $('.show-'+id).addClass('layui-btn-normal').removeClass('layui-btn-warm').text('已处理').attr('state',stat);
                          }
                        }
           })
          }
        </script>

{/block}
